﻿using Prism.Events;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using wpfForPrism.ViewModels;

namespace wpfForPrism.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly IEventAggregator eventAggregatorv;

        public MainWindow(IEventAggregator eventAggregatorv)
        {
            InitializeComponent();
            Loaded += (s,e) => {
                var dc = (MainWindowViewModel)DataContext;
                dc.ShowContentFunc("A");
            };
            this.eventAggregatorv = eventAggregatorv;
        }
        /// <summary>
        /// 发布
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnPub_Click(object sender, RoutedEventArgs e)
        {
            eventAggregatorv.GetEvent<MsgEvent>().Publish("发布消息");
        }

        private void BtnSub_Click(object sender, RoutedEventArgs e)
        {
            eventAggregatorv.GetEvent<MsgEvent>().Subscribe(SUb);

        }

        private void BtnCancelSub_Click(object sender, RoutedEventArgs e)
        {
            eventAggregatorv.GetEvent<MsgEvent>().Unsubscribe(SUb);
        }

        private void SUb(string msg) { MessageBox.Show(msg); }
    }
}